package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.pojos.ApUser;
import com.heima.model.wemedia.dtos.CommetStatusDtos;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.utils.thread.ApThreadLocalUtil;
import com.heima.utils.thread.WmThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Slf4j
@Transactional
public class ArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ArticleConfigService {
    @Override
    public void UpdateByArticleId(Map map) {
        Long articleId = (Long) map.get("articleId");
        Object enable = map.get("enable");
        boolean flag = true;
        if (enable.equals(1)) flag = false;
        LambdaUpdateWrapper<ApArticleConfig> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ApArticleConfig::getArticleId, articleId)
                .set(ApArticleConfig::getIsDown, flag);
        update(wrapper);
    }

    @Override
    public Boolean UpdateByArticleIdIsComment(CommetStatusDtos dto) {
        //根据文章id修改is_comment
        //校验数据
        if (dto == null) {
            return false;
        }
        //检验是否登录
        /* ApUser apUser = ApThreadLocalUtil.getApUser();
        if (apUser == null) {
            return false;
        }*/
        log.error("已调用");
        //log.error("远程调用成功，传入的是{}，当前登录用户是{}",dto,apUser);
        LambdaUpdateWrapper<ApArticleConfig> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ApArticleConfig::getArticleId, dto.getArticleId())
                .set(ApArticleConfig::getIsComment, dto.getOperation());
        return update(wrapper);
    }
}
